﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;

namespace CNotebook
{
    public class CompanyManager:ConnectionManager
    {
        public bool IsExists(string sBranchName)
        {
            SqlCommand oCommand = new SqlCommand();
            SqlDataAdapter oAdapter = new SqlDataAdapter();
            DataSet ds = new DataSet();

            oCommand.Connection = this.Connection;
            oCommand.CommandType = CommandType.Text;
            oCommand.CommandText = "SELECT * FROM Company WHERE CompanyName=@CompanyName";
            oCommand.Parameters.Add(new SqlParameter("@CompanyName", sBranchName));

            oAdapter.SelectCommand = oCommand;
            oAdapter.Fill(ds);

            int iCount;

            iCount = ds.Tables[0].Rows.Count;


            if (iCount > 0)
            {
                return true;
            }
            else
            {
                return false;
            }

        }

        public DataTable BrowseCompany()
        {
            SqlCommand oCommand = new SqlCommand();
            SqlDataAdapter oAdapter = new SqlDataAdapter();
            DataSet ds = new DataSet();

            oCommand.Connection = this.Connection;
            oCommand.CommandType = CommandType.Text;
            oCommand.CommandText = "SELECT * FROM Company";

            oAdapter.SelectCommand = oCommand;
            oAdapter.Fill(ds);

            return ds.Tables[0];
        }
    }
}
